home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / CaptureScr2152985232009.psc / AVItoGIF 1.0 / AVI2GiffMain.frm < prev    next >
Text File  |  2008-03-27  |  24KB  |  769 lines

  1. VERSION 5.00
  2. Begin VB.Form AVI2Gif 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "AVItoGIF"
  5.    ClientHeight    =   5550
  6.    ClientLeft      =   45
  7.    ClientTop       =   615
  8.    ClientWidth     =   7695
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11.       Name            =   "Tahoma"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   400
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "AVI2GiffMain.frx":0000
  20.    LinkTopic       =   "Form1"
  21.    LockControls    =   -1  'True
  22.    MaxButton       =   0   'False
  23.    ScaleHeight     =   370
  24.    ScaleMode       =   3  'Pixel
  25.    ScaleWidth      =   513
  26.    StartUpPosition =   2  'CenterScreen
  27.    Begin VB.PictureBox iPalette 
  28.       BackColor       =   &H00FFFFFF&
  29.       ClipControls    =   0   'False
  30.       ForeColor       =   &H00808080&
  31.       Height          =   1500
  32.       Left            =   6000
  33.       ScaleHeight     =   96
  34.       ScaleMode       =   3  'Pixel
  35.       ScaleWidth      =   96
  36.       TabIndex        =   8
  37.       TabStop         =   0   'False
  38.       Top             =   1335
  39.       Width           =   1500
  40.    End
  41.    Begin VB.Timer tmrDelay 
  42.       Enabled         =   0   'False
  43.       Left            =   5220
  44.       Top             =   4620
  45.    End
  46.    Begin VB.CommandButton cmdPickColor 
  47.       Caption         =   "Pick &color"
  48.       Enabled         =   0   'False
  49.       Height          =   405
  50.       Left            =   6000
  51.       TabIndex        =   11
  52.       TabStop         =   0   'False
  53.       Top             =   3960
  54.       Width           =   1170
  55.    End
  56.    Begin VB.CheckBox chkTransparent 
  57.       Appearance      =   0  'Flat
  58.       Caption         =   "&Transparent"
  59.       Enabled         =   0   'False
  60.       ForeColor       =   &H80000008&
  61.       Height          =   240
  62.       Left            =   6000
  63.       TabIndex        =   10
  64.       TabStop         =   0   'False
  65.       Top             =   3600
  66.       Width           =   1335
  67.    End
  68.    Begin AVItoGIF.ucCanvas ucCanvas 
  69.       Height          =   5025
  70.       Left            =   120
  71.       TabIndex        =   0
  72.       TabStop         =   0   'False
  73.       Top             =   165
  74.       Width           =   5685
  75.       _ExtentX        =   10028
  76.       _ExtentY        =   8864
  77.    End
  78.    Begin AVItoGIF.ucProgress ucProgress 
  79.       Align           =   2  'Align Bottom
  80.       Height          =   225
  81.       Left            =   0
  82.       Top             =   5325
  83.       Width           =   7695
  84.       _ExtentX        =   13573
  85.       _ExtentY        =   397
  86.       BorderStyle     =   1
  87.    End
  88.    Begin VB.Label lblEntriesV 
  89.       Alignment       =   1  'Right Justify
  90.       ForeColor       =   &H80000015&
  91.       Height          =   210
  92.       Left            =   6375
  93.       TabIndex        =   9
  94.       Top             =   2865
  95.       Width           =   1125
  96.    End
  97.    Begin VB.Label lblPaletteV 
  98.       Height          =   195
  99.       Left            =   6675
  100.       TabIndex        =   7
  101.       Top             =   1005
  102.       Width           =   900
  103.    End
  104.    Begin VB.Label lblPalette 
  105.       Caption         =   "Palette:"
  106.       Height          =   195
  107.       Left            =   6015
  108.       TabIndex        =   6
  109.       Top             =   1005
  110.       Width           =   735
  111.    End
  112.    Begin VB.Label Label1 
  113.       Caption         =   "Note: Enable/disable transparency before GIF optimization."
  114.       ForeColor       =   &H80000015&
  115.       Height          =   660
  116.       Left            =   6000
  117.       TabIndex        =   12
  118.       Top             =   4590
  119.       Width           =   1575
  120.       WordWrap        =   -1  'True
  121.    End
  122.    Begin VB.Label lblScreenV 
  123.       Height          =   195
  124.       Left            =   6675
  125.       TabIndex        =   3
  126.       Top             =   450
  127.       Width           =   900
  128.    End
  129.    Begin VB.Label lblFramesV 
  130.       Height          =   195
  131.       Left            =   6675
  132.       TabIndex        =   5
  133.       Top             =   720
  134.       Width           =   900
  135.    End
  136.    Begin VB.Label lblScreen 
  137.       Caption         =   "Screen:"
  138.       Height          =   195
  139.       Left            =   6015
  140.       TabIndex        =   2
  141.       Top             =   450
  142.       Width           =   735
  143.    End
  144.    Begin VB.Label lblFrames 
  145.       Caption         =   "Frames:"
  146.       Height          =   195
  147.       Left            =   6015
  148.       TabIndex        =   4
  149.       Top             =   720
  150.       Width           =   735
  151.    End
  152.    Begin VB.Label lblInfo 
  153.       Caption         =   "GIF info:"
  154.       BeginProperty Font 
  155.          Name            =   "Tahoma"
  156.          Size            =   8.25
  157.          Charset         =   0
  158.          Weight          =   700
  159.          Underline       =   0   'False
  160.          Italic          =   0   'False
  161.          Strikethrough   =   0   'False
  162.       EndProperty
  163.       Height          =   210
  164.       Left            =   6015
  165.       TabIndex        =   1
  166.       Top             =   150
  167.       Width           =   1260
  168.    End
  169.    Begin VB.Menu mnuFileTop 
  170.       Caption         =   "&File"
  171.       Begin VB.Menu mnuFile 
  172.          Caption         =   "&Import AVI..."
  173.          Index           =   0
  174.          Shortcut        =   ^I
  175.       End
  176.       Begin VB.Menu mnuFile 
  177.          Caption         =   "&Save test GIF"
  178.          Index           =   1
  179.          Shortcut        =   ^S
  180.       End
  181.       Begin VB.Menu mnuFile 
  182.          Caption         =   "-"
  183.          Index           =   2
  184.       End
  185.       Begin VB.Menu mnuFile 
  186.          Caption         =   "&Optimize GIF"
  187.          Index           =   3
  188.          Shortcut        =   ^O
  189.       End
  190.       Begin VB.Menu mnuFile 
  191.          Caption         =   "-"
  192.          Index           =   4
  193.       End
  194.       Begin VB.Menu mnuFile 
  195.          Caption         =   "E&xit"
  196.          Index           =   5
  197.       End
  198.    End
  199.    Begin VB.Menu mnuOptionsTop 
  200.       Caption         =   "&Options"
  201.       Begin VB.Menu mnuOptions 
  202.          Caption         =   "Ordered dither"
  203.          Index           =   0
  204.       End
  205.       Begin VB.Menu mnuOptions 
  206.          Caption         =   "Use optimal (first frame)"
  207.          Index           =   1
  208.       End
  209.    End
  210.    Begin VB.Menu mnuHelpTop 
  211.       Caption         =   "&Help"
  212.       Begin VB.Menu mnuHelp 
  213.          Caption         =   "&About"
  214.          Index           =   0
  215.       End
  216.    End
  217. End
  218. Attribute VB_Name = "AVI2Gif"
  219. Attribute VB_GlobalNameSpace = False
  220. Attribute VB_Creatable = False
  221. Attribute VB_PredeclaredId = True
  222. Attribute VB_Exposed = False
  223. '================================================
  224. ' Project:       AVItoGIF
  225. ' Author:        Carles P.V. (*)
  226. ' Last revision: 2003.09.06
  227. '================================================
  228. ' Commercial use not permitted!
  229. ' Email author/s please.
  230. '================================================
  231. '
  232. ' (*) All thanks to Vlad Vissoultchev & Ron van Tilburg
  233. '     for GIF Decode/Encode original routines.
  234. '
  235. ' Notes:
  236. '
  237. ' This 'AVI to GIF' converter is quite 'simple':
  238. ' - Optimal palette is got from the first frame.
  239. ' - Simple GIF size optimization (M.B.R.).
  240. '
  241. ' I'm working now on better GIF optimization. I'll post
  242. ' it as soon as possible (I hope).
  243. '
  244. ' Please, let me know for any bug/s, speed improvements,
  245. ' etc. Thanks.
  246.  
  247.  
  248.  
  249. Option Explicit
  250.  
  251. Private m_oGIF            As New cGIF  ' Our GIF object
  252. Private m_oBackground     As New cTile ' Frame rendering
  253. Private m_oDIBRestore     As New cDIB  ' Frame rendering
  254. Private m_bTransparent    As Boolean   ' Transparency
  255. Private m_nTransparentIdx As Integer   ' Transparent palette entry
  256. Private m_nFrame          As Integer   ' Current frame
  257. Private m_nFrames         As Integer   ' Number of frames
  258.  
  259. Private m_sFilename       As String    ' Last file path (AVI import)
  260. Private m_bPicking        As Boolean   ' Picking transparent color
  261. Dim AVIFile As String
  262. Dim sTmpFilename As String
  263.  
  264. Private Sub Form_Activate()
  265. Dim Strng As String
  266.     If Command$ <> "" And Left(Command$, 1) <> "1" Then
  267.         AVIFile = App.Path & "\MyAVI.avi"
  268.         ImportAVI
  269.         Optimum
  270.         SaveGif
  271.         Unload Me
  272.     End If
  273.     If Command$ <> "" And Left(Command$, 1) = "1" Then
  274.         AVIFile = App.Path & "\MyAVI.avi"
  275.         ImportAVI
  276.         'Optimum
  277.         'SaveGif
  278.     End If
  279.     'With mnuOptions(1)
  280.         '.Checked = Not .Checked
  281.         'mDither8bpp.Palette = -.Checked * [ipOptimal]
  282.     'End With
  283.     'With mnuOptions(0)
  284.         '.Checked = Not .Checked
  285.         'mDither8bpp.DitherMethod = -.Checked * [idmOrdered]
  286.     'End With
  287. 'mnuOptions_Click (0)
  288. 'mnuOptions_Click (1)
  289.  
  290. End Sub
  291.  
  292. '//
  293.  
  294. Private Sub Form_Load()
  295. SetTopMostWindow Me.hWnd, True
  296.     '-- Initalize mDither8bpp module
  297.     mDither8bpp.InitializeLUTs
  298.     mDither8bpp.Palette = [ipBrowser]
  299.     mDither8bpp.DitherMethod = [idmNone]
  300.     
  301.     '-- Initalize pattern brush (empty palette entry)
  302.     mMisc.InitializePatternBrush
  303.             
  304.     '-- Load canvas custom cursor
  305.     Set ucCanvas.UserIcon = LoadResPicture("CURSOR_PICKCOLOR", vbResCursor)
  306.     
  307.     '-- Hook mouse wheel for zooming support
  308.     mWheel.HookWheel
  309. End Sub
  310.  
  311. Private Sub Form_Paint()
  312.  
  313.     '-- Some decorative lines
  314.     Me.Line (0, 0)-(ScaleWidth, 0), vb3DShadow
  315.     Me.Line (0, 1)-(ScaleWidth, 1), vb3DHighlight
  316. End Sub
  317.  
  318. Private Sub Form_Unload(Cancel As Integer)
  319.  
  320.     '-- Destroy GIF and rendering buffers
  321.     pvCleanUp
  322.     '-- Destroy pattern brush (empty palette entry)
  323.     mMisc.DestroyPatternBrush
  324.     
  325.     '-- Is next line necessary [?]
  326.     Set AVI2Gif = Nothing
  327.     End
  328. End Sub
  329.  
  330. '//
  331.  
  332. Private Sub mnuFile_Click(Index As Integer)
  333.     
  334.   
  335.     Select Case Index
  336.     
  337.         Case 0 '-- Import AVI...
  338.         
  339.             '-- Show open file dialog
  340.             sTmpFilename = mDialogFile.GetFileName(m_sFilename, "AVI files (*.avi)|*.AVI", , "Load AVI file", -1)
  341.             'sTmpFilename = AVIFile
  342.             If (Len(sTmpFilename)) Then
  343.                 m_sFilename = sTmpFilename
  344.                 
  345.                 '-- Stop animation
  346.                 tmrDelay.Enabled = 0
  347.             
  348.                 '-- Destroy current GIF
  349.                 m_oGIF.Destroy
  350.                 
  351.                 '-- Disable transparency
  352.                 chkTransparent.Enabled = -1
  353.                 chkTransparent = 0
  354.                 cmdPickColor.Enabled = 0
  355.                 m_bTransparent = 0
  356.                 m_nTransparentIdx = 0
  357.                 
  358.                 '-- Import AVI frames...
  359.                 DoEvents
  360.                 If (mAVIImp.ImportAVI(m_sFilename, m_oGIF, ucProgress)) Then
  361.                     pvInitialize
  362.                     pvShowInfo
  363.                   Else
  364.                     MsgBox "Unexpected error loading AVI file.", vbExclamation
  365.                     pvCleanUp
  366.                     pvShowInfo
  367.                 End If
  368.             End If
  369.              
  370.         Case 1 '-- Save GIF...
  371.             
  372.             If (m_oGIF.FramesCount = 0) Then
  373.                 
  374.                 '-- No GIF
  375.                 MsgBox "Nothing to save", vbExclamation
  376.               
  377.               Else
  378.                 '-- Save as test file (Test.gif)
  379.                 DoEvents
  380.                 Screen.MousePointer = vbArrowHourglass
  381.                 If (Not m_oGIF.Save(App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & "Test.gif")) Then
  382.                     Screen.MousePointer = vbDefault
  383.                     MsgBox "Unexpected error saving GIF file.", vbExclamation
  384.                   Else
  385.                     Screen.MousePointer = vbDefault
  386.                 End If
  387.             End If
  388.             
  389.         Case 3 ' -- Optimize GIF
  390.             
  391.             If (m_oGIF.FramesCount = 0) Then
  392.             
  393.                 '-- Nothing to optimize
  394.                 MsgBox "Nothing to optimize", vbExclamation
  395.                 
  396.               Else
  397.                 '-- Remove unused entries and get minimum bounding rectangles
  398.                 tmrDelay.Enabled = 0
  399.                 DoEvents
  400.                 mGIFExt.OptimizeGlobalPalette m_oGIF, ucProgress: m_nTransparentIdx = m_oGIF.FrameTransparentColorIndex(1)
  401.                 mGIFExt.OptimizeFrames m_oGIF, ucProgress
  402.                 '-- Initialize
  403.                 pvInitialize
  404.                 pvShowInfo
  405.                 '-- Disable transparency controls
  406.                 chkTransparent.Enabled = 0
  407.                 cmdPickColor.Enabled = 0
  408.                 '-- Disable Picking mode [?]
  409.                 If (m_bPicking) Then
  410.                     m_bPicking = 0
  411.                     ucCanvas.WorkMode = [cnvScrollMode]
  412.                 End If
  413.             End If
  414.             
  415.         Case 5 ' -- Exit
  416.             Unload Me
  417.     End Select
  418. End Sub
  419. Private Sub Optimum()
  420.                 tmrDelay.Enabled = 0
  421.                 DoEvents
  422.                 mGIFExt.OptimizeGlobalPalette m_oGIF, ucProgress: m_nTransparentIdx = m_oGIF.FrameTransparentColorIndex(1)
  423.                 mGIFExt.OptimizeFrames m_oGIF, ucProgress
  424.                 '-- Initialize
  425.                 pvInitialize
  426.                 pvShowInfo
  427.                 '-- Disable transparency controls
  428.                 chkTransparent.Enabled = 0
  429.                 cmdPickColor.Enabled = 0
  430.                 '-- Disable Picking mode [?]
  431.                 If (m_bPicking) Then
  432.                     m_bPicking = 0
  433.                     ucCanvas.WorkMode = [cnvScrollMode]
  434.                 End If
  435. End Sub
  436. Private Sub SaveGif()
  437.             If (m_oGIF.FramesCount = 0) Then
  438.                 
  439.                 '-- No GIF
  440.                 MsgBox "Nothing to save", vbExclamation
  441.               
  442.               Else
  443.                 '-- Save as test file (Test.gif)
  444.                 DoEvents
  445.                 Screen.MousePointer = vbArrowHourglass
  446.                 If (Not m_oGIF.Save(App.Path & IIf(Right$(App.Path, 1) <> "\", "\", "") & "Test.gif")) Then
  447.                     Screen.MousePointer = vbDefault
  448.                     MsgBox "Unexpected error saving GIF file.", vbExclamation
  449.                   Else
  450.                     Screen.MousePointer = vbDefault
  451.                 End If
  452.             End If
  453.  
  454. End Sub
  455. Private Sub ImportAVI()
  456.             '-- Show open file dialog
  457.             'sTmpFilename = mDialogFile.GetFileName(m_sFilename, "AVI files (*.avi)|*.AVI", , "Load AVI file", -1)
  458.             sTmpFilename = AVIFile
  459.             If (Len(sTmpFilename)) Then
  460.                 m_sFilename = sTmpFilename
  461.                 
  462.                 '-- Stop animation
  463.                 tmrDelay.Enabled = 0
  464.             
  465.                 '-- Destroy current GIF
  466.                 m_oGIF.Destroy
  467.                 
  468.                 '-- Disable transparency
  469.                 chkTransparent.Enabled = -1
  470.                 chkTransparent = 0
  471.                 cmdPickColor.Enabled = 0
  472.                 m_bTransparent = 0
  473.                 m_nTransparentIdx = 0
  474.                 
  475.                 '-- Import AVI frames...
  476.                 DoEvents
  477.                 If (mAVIImp.ImportAVI(m_sFilename, m_oGIF, ucProgress)) Then
  478.                     pvInitialize
  479.                     pvShowInfo
  480.                   Else
  481.                     MsgBox "Unexpected error loading AVI file.", vbExclamation
  482.                     pvCleanUp
  483.                     pvShowInfo
  484.                 End If
  485.             End If
  486.  
  487. End Sub
  488. Private Sub mnuOptions_Click(Index As Integer)
  489.  
  490.     Select Case Index
  491.     
  492.         Case 0 '-- Ordered dither
  493.             With mnuOptions(0)
  494.                 .Checked = Not .Checked
  495.                 mDither8bpp.DitherMethod = -.Checked * [idmOrdered]
  496.             End With
  497.             
  498.         Case 1 '-- Use optimal
  499.             With mnuOptions(1)
  500.                 .Checked = Not .Checked
  501.                 mDither8bpp.Palette = -.Checked * [ipOptimal]
  502.             End With
  503.     End Select
  504. End Sub
  505.  
  506. Private Sub mnuHelp_Click(Index As Integer)
  507.                 
  508.     '-- Simple About box...
  509.     MsgBox "AVItoGIF v" & App.Major & "." & App.Minor & vbCrLf & vbCrLf & _
  510.            "Simple AVI to GIF converter + Basic GIF size optimization" & vbCrLf & vbCrLf & _
  511.            "All thanks to Vlad Vissoultchev & Ron van Tilburg" & vbCrLf & _
  512.            "for GIF Decode/Encode original routines."
  513. End Sub
  514.  
  515. '//
  516.  
  517. Private Sub chkTransparent_Click()
  518.   
  519.   Dim nFrm As Integer
  520.     
  521.     If (m_oGIF.FramesCount) Then
  522.     
  523.         '-- Update controls
  524.         m_bTransparent = -chkTransparent
  525.         cmdPickColor.Enabled = -chkTransparent
  526.     
  527.         '-- Re-mask frames
  528.         Screen.MousePointer = vbHourglass
  529.         mGIFExt.RemaskFrames m_oGIF, m_bTransparent, m_nTransparentIdx, ucProgress
  530.         Screen.MousePointer = vbDefault
  531.         
  532.         '-- Re-start animation
  533.         pvInitialize
  534.     End If
  535. End Sub
  536.  
  537. Private Sub cmdPickColor_Click()
  538.  
  539.     '-- Enable color picking
  540.     If (m_bTransparent) Then
  541.         m_bPicking = -1
  542.         ucCanvas.WorkMode = [cnvUserMode]
  543.         
  544.         '-- Show first (full) frame
  545.         tmrDelay.Enabled = 0
  546.         m_nFrame = 1
  547.         pvFrame_Change
  548.     End If
  549. End Sub
  550.  
  551. '//
  552.  
  553. Private Sub ucCanvas_MouseDown(Button As Integer, Shift As Integer, X As Long, Y As Long)
  554.     
  555.     '-- Force ucCanvas_MouseMove sub.
  556.     If (m_bPicking And ucCanvas.DIB.hDIB <> 0) Then
  557.         ucCanvas_MouseMove Button, Shift, X, Y
  558.     End If
  559. End Sub
  560.  
  561. Private Sub ucCanvas_MouseMove(Button As Integer, Shift As Integer, X As Long, Y As Long)
  562.     
  563.     If (Button = vbLeftButton) Then
  564.     
  565.         If (m_bPicking And m_oGIF.FramesCount) Then
  566.             
  567.             With m_oGIF
  568.             
  569.                 If (X >= .FrameLeft(1) And _
  570.                     Y >= .FrameTop(1) And _
  571.                     X < .FrameDIBXOR(1).Width - .FrameLeft(1) And _
  572.                     Y < .FrameDIBXOR(1).Height - .FrameTop(1)) Then
  573.                     
  574.                     '-- Get palette index (NOT color)
  575.                     m_nTransparentIdx = mDither8bpp.PaletteIndex(.FrameDIBXOR(m_nFrame), X + .FrameLeft(1), Y + .FrameTop(1))
  576.                 End If
  577.             End With
  578.         End If
  579.     End If
  580. End Sub
  581.  
  582. Private Sub ucCanvas_MouseUp(Button As Integer, Shift As Integer, X As Long, Y As Long)
  583.     
  584.   Dim nFrm As Integer
  585.   Dim lClr As Long
  586.     
  587.     Select Case Button
  588.     
  589.         Case vbLeftButton
  590.         
  591.             If (m_bPicking) Then
  592.                 m_bPicking = 0
  593.                 ucCanvas.WorkMode = [cnvScrollMode]
  594.                 
  595.                 '-- Re-mask frames
  596.                 Screen.MousePointer = vbHourglass
  597.                 mGIFExt.RemaskFrames m_oGIF, m_bTransparent, m_nTransparentIdx, ucProgress
  598.                 Screen.MousePointer = vbDefault
  599.                 
  600.                 '-- Re-start animation
  601.                 pvInitialize
  602.             End If
  603.         
  604.         Case vbRightButton
  605.             
  606.             '-- Change background color
  607.             lClr = mDialogColor.SelectColor(Me.hWnd, ucCanvas.BackColor)
  608.             If (lClr <> -1) Then
  609.                 ucCanvas.BackColor = lClr
  610.                 If (m_oGIF.FramesCount) Then pvInitialize
  611.             End If
  612.     End Select
  613. End Sub
  614.  
  615. '//
  616.  
  617. Private Sub pvCleanUp()
  618.     
  619.     Set m_oGIF = Nothing
  620.     Set ucCanvas.DIB = Nothing
  621.     Set m_oBackground = Nothing
  622.     Set m_oDIBRestore = Nothing
  623. End Sub
  624.  
  625. Private Sub pvInitialize()
  626.  
  627.     '-- Stop timer
  628.     tmrDelay.Enabled = 0
  629.     
  630.     '-- Paint palette
  631.     pvPaintPalette
  632.  
  633.     '-- Initialize buffers
  634.     With m_oGIF
  635.     
  636.         '-- Get number of frames
  637.         m_nFrames = .FramesCount
  638.         
  639.         '-- Create canvas DIB
  640.         ucCanvas.DIB.Create .ScreenWidth, .ScreenHeight, [32_bpp]
  641.         ucCanvas.Resize
  642.         '-- Create restoring DIB
  643.         m_oDIBRestore.Create .ScreenWidth, .ScreenHeight, [24_bpp]
  644.         '-- Create background pattern (solid color) and initialize DIBs
  645.         m_oBackground.SetPatternFromSolidColor ucCanvas.BackColor
  646.         m_oBackground.Tile ucCanvas.DIB.hDC, 0, 0, .ScreenWidth, .ScreenHeight
  647.         m_oBackground.Tile m_oDIBRestore.hDC, 0, 0, .ScreenWidth, .ScreenHeight
  648.        
  649.         '-- Start animation [?]
  650.         If (m_nFrames > 1) Then
  651.             '-- Enable timer
  652.             m_nFrame = m_nFrames
  653.             tmrDelay.Interval = 1
  654.             tmrDelay.Enabled = -1
  655.           Else
  656.             '-- Render only first frame
  657.             .FrameDraw ucCanvas.DIB.hDC, 1: ucCanvas.Repaint
  658.         End If
  659.     End With
  660. End Sub
  661.  
  662. Private Sub tmrDelay_Timer()
  663.     
  664.     '-- Next frame / First
  665.     If (m_nFrame < m_nFrames) Then
  666.         m_nFrame = m_nFrame + 1
  667.       Else
  668.         m_nFrame = 1
  669.     End If
  670.     pvFrame_Change
  671. End Sub
  672.  
  673. Private Sub pvFrame_Change()
  674.     
  675.     With m_oGIF
  676.         
  677.         '-- Set current frame delay
  678.         Select Case .FrameDelay(m_nFrame)
  679.             Case Is < 0
  680.                 tmrDelay.Interval = 60000 ' Max.: 1 min.
  681.             Case Is = 0
  682.                 tmrDelay.Interval = 100   ' Def.: 0.1 sec.
  683.             Case Is < 5
  684.                 tmrDelay.Interval = 50    ' Min.: 0.05 sec.
  685.             Case Else
  686.                 tmrDelay.Interval = .FrameDelay(m_nFrame) * 10
  687.         End Select
  688.         
  689.         '-- Restore:
  690.         If (m_nFrame = 1) Then
  691.             m_oBackground.Tile ucCanvas.DIB.hDC, 0, 0, .ScreenWidth, .ScreenHeight
  692.           Else
  693.             ucCanvas.DIB.LoadBlt m_oDIBRestore.hDC
  694.         End If
  695.         
  696.         '-- Draw current frame:
  697.         .FrameDraw ucCanvas.DIB.hDC, m_nFrame
  698.         
  699.         '-- Update restoring buffer:
  700.         Select Case .FrameDisposalMethod(m_nFrame)
  701.             Case [dmNotSpecified], [dmDoNotDispose]
  702.                 '-- Update from current
  703.                 m_oDIBRestore.LoadBlt ucCanvas.DIB.hDC
  704.             Case [dmRestoreToBackground]
  705.                 '-- Update from background
  706.                 m_oBackground.Tile m_oDIBRestore.hDC, .FrameLeft(m_nFrame), .FrameTop(m_nFrame), .FrameDIBXOR(m_nFrame).Width, .FrameDIBXOR(m_nFrame).Height, 0
  707.             Case [dmRestoreToPrevious]
  708.                 '-- Preserve buffer
  709.         End Select
  710.     End With
  711.     
  712.     '-- Paint frame
  713.     ucCanvas.Repaint
  714. End Sub
  715.  
  716. Private Sub pvShowInfo()
  717.     
  718.   Dim aBPP As Byte
  719.   
  720.     Select Case True
  721.     
  722.         Case ucCanvas.DIB.hDIB <> 0
  723.             '-- Calc. GIF palette color depth
  724.             Do: aBPP = aBPP + 1
  725.             Loop Until 2 ^ aBPP >= m_oGIF.GlobalPaletteEntries
  726.             '-- Show AVI props.
  727.             lblScreenV.Caption = m_oGIF.ScreenWidth & "x" & m_oGIF.ScreenHeight
  728.             lblFramesV.Caption = m_oGIF.FramesCount
  729.             lblPaletteV.Caption = aBPP & " bpp"
  730.             lblEntriesV.Caption = m_oGIF.GlobalPaletteEntries & " entries"
  731.             
  732.         Case ucCanvas.DIB.hDIB = 0
  733.             '-- Reset AVI props.
  734.             lblScreenV.Caption = ""
  735.             lblFramesV.Caption = ""
  736.             lblPaletteV.Caption = ""
  737.             lblEntriesV.Caption = ""
  738.     End Select
  739. End Sub
  740.  
  741. '//
  742.  
  743. Private Sub iPalette_Paint()
  744.     pvPaintPalette
  745. End Sub
  746.  
  747. Private Sub pvPaintPalette()
  748.   
  749.   Dim i As Long, j As Long
  750.   Dim lIdx As Long
  751.   Dim lClr As Long
  752.     
  753.     '-- Show the 256 entries
  754.     For i = 0 To 90 Step 6
  755.         For j = 0 To 90 Step 6
  756.             With m_oGIF
  757.                 If (lIdx < .GlobalPaletteEntries) Then
  758.                     lClr = .GlobalPaletteRGBEntry(lIdx)
  759.                   Else
  760.                     lClr = -1
  761.                 End If
  762.                 mMisc.DrawRectangle iPalette.hDC, j, i, j + 6, i + 6, lClr
  763.                 lIdx = lIdx + 1
  764.             End With
  765.         Next j
  766.     Next i
  767. End Sub
  768.  
  769.